package com.woniuxy.project.campus.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.project.campus.account.model.RoleAccount;
import com.woniuxy.project.campus.account.mapper.RoleAccountMapper;
import com.woniuxy.project.campus.account.service.RoleAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.project.campus.util.StaticData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年02月17日
 */
@Service
public class RoleAccountServiceImpl extends ServiceImpl<RoleAccountMapper, RoleAccount> implements RoleAccountService {

    @Resource
    private RoleAccountMapper roleAccountMapper;
    @Override
    public RoleAccount getRoleId(Integer id) {
        QueryWrapper<RoleAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_id",id);
        RoleAccount roleAccount = roleAccountMapper.selectOne(queryWrapper);
        if(roleAccount==null){
            throw new RuntimeException("该用户没有角色");
        }
        return roleAccount;
    }

    @Override
    public void updateRoleId(Integer accountId) {
        QueryWrapper<RoleAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_id",accountId);
        RoleAccount roleAccount = roleAccountMapper.selectOne(queryWrapper);
        if(roleAccount==null){
            throw new RuntimeException("该用户没有角色");
        }
        roleAccount.setRoleId(StaticData.SHOP_ROLE_ID);
        roleAccountMapper.updateById(roleAccount);
    }
}
